package com.zero.ava.cluster;

import java.util.Set;

import com.hazelcast.config.Config;
import com.hazelcast.config.JoinConfig;
import com.hazelcast.config.NetworkConfig;
import com.hazelcast.core.Cluster;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.Member;
import com.hazelcast.core.MemberAttributeEvent;
import com.hazelcast.core.MembershipEvent;
import com.hazelcast.core.MembershipListener;
import com.hazelcast.core.MultiMap;

public class TCluster {
	public static void main(String[] args) {
		Config config = new Config();
		NetworkConfig networkConfig = config.getNetworkConfig();
		networkConfig.getInterfaces().setEnabled(true);
		networkConfig.setPort(5701);

		JoinConfig join = networkConfig.getJoin();
		// join.getMulticastConfig().setEnabled(true);
		join.getTcpIpConfig().setEnabled(true);

		join.getTcpIpConfig().addMember("10.248.40.49:5701");
		join.getTcpIpConfig().addMember("10.248.114.58:5701");

		networkConfig.getInterfaces().addInterface("10.248.114.58");
		HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(config);
		Cluster cluster = hazelcast.getCluster();
		cluster.addMembershipListener(new MembershipListener() {

			@Override
			public void memberRemoved(MembershipEvent membershipEvent) {
				// TODO Auto-generated method stub

			}

			@Override
			public void memberAttributeChanged(MemberAttributeEvent memberAttributeEvent) {
				// TODO Auto-generated method stub

			}

			@Override
			public void memberAdded(MembershipEvent membershipEvent) {
				// TODO Auto-generated method stub

			}
		});

		MultiMap<Object, Object> multiMap = hazelcast.getMultiMap("Frist");
		multiMap.put(2, "hello");
		System.out.println(multiMap.get(1));
	}
}
